import { createSSRApp } from "vue";
import App from "./App.vue";
import uviewPlus from 'uview-plus';
import axios from "axios";

// 配置axios默认设置
axios.defaults.baseURL = 'http://localhost:8055/api';
axios.defaults.withCredentials = true;

// 添加请求拦截器
axios.interceptors.request.use(config => {
  config.headers['Content-Type'] = 'application/json';
  return config;
});

// 添加响应拦截器
axios.interceptors.response.use(
  response => response,
  error => {
    if (error.code === 'ERR_NETWORK') {
      console.error('网络错误 - 请检查后端服务是否运行');
    }
    return Promise.reject(error);
  }
);

export function createApp() {
  const app = createSSRApp(App);
  app.use(uviewPlus)
  app.use(axios)
  
  return {
    app,
  };
}
